package com.coolgor.coldot.dao.stock;

import com.coolgor.coldot.entity.stock.StockSpecialDay;
import org.apache.ibatis.annotations.*;
import java.util.List;


@Mapper
public interface StockSpecialDayDao {

	@Select("""
		<script>
			SELECT
				*
			FROM
				tb_coldot_stock_special_day
			WHERE
				record_id = #{recordID}
		</script>
	""")
	@Results(id = "StockSpecialDayMap", value = {
		@Result(property = "recordID", column = "record_id"),
		@Result(property = "beginDate", column = "begin_date"),
		@Result(property = "endDate", column = "end_date"),
		@Result(property = "category", column = "category"),
		@Result(property = "context", column = "context"),
		@Result(property = "flag", column = "flag"),
		@Result(property = "createTime", column = "create_time"),
		@Result(property = "lastEditTime", column = "last_edit_time"),
		@Result(property = "remark", column = "remark")
	})
	StockSpecialDay queryByID(@Param("recordID") Long recordID);

	@Select("""
		<script>
			SELECT
				*
			FROM
				tb_coldot_stock_special_day
			<where>
				<if test="stockSpecialDayCondition.recordID != null">
					and record_id = #{stockSpecialDayCondition.recordID}
				</if>
				<if test="stockSpecialDayCondition.beginDate != null">
					and begin_date = #{stockSpecialDayCondition.beginDate}
				</if>
				<if test="stockSpecialDayCondition.beginDate != null">
					and <![CDATA[ begin_date >= #{stockSpecialDayCondition.beginDate,jdbcType=DATE} ]]>
				</if>
				<if test="stockSpecialDayCondition.beginDate != null">
					and <![CDATA[ begin_date <= #{stockSpecialDayCondition.beginDate,jdbcType=DATE} ]]>
				</if>
				<if test="stockSpecialDayCondition.endDate != null">
					and end_date = #{stockSpecialDayCondition.endDate}
				</if>
				<if test="stockSpecialDayCondition.endDate != null">
					and <![CDATA[ end_date >= #{stockSpecialDayCondition.endDate,jdbcType=DATE} ]]>
				</if>
				<if test="stockSpecialDayCondition.endDate != null">
					and <![CDATA[ end_date <= #{stockSpecialDayCondition.endDate,jdbcType=DATE} ]]>
				</if>
				<if test="stockSpecialDayCondition.category != null">
					and category = #{stockSpecialDayCondition.category}
				</if>
				<if test="stockSpecialDayCondition.context != null">
					and context like '${stockSpecialDayCondition.context}'
				</if>
				<if test="stockSpecialDayCondition.flag != null">
					and flag = #{stockSpecialDayCondition.flag}
				</if>
				<if test="stockSpecialDayCondition.createTime != null">
					and create_time = #{stockSpecialDayCondition.createTime}
				</if>
				<if test="stockSpecialDayCondition.createTime != null">
					and <![CDATA[ create_time >= #{stockSpecialDayCondition.createTime,jdbcType=DATE} ]]>
				</if>
				<if test="stockSpecialDayCondition.createTime != null">
					and <![CDATA[ create_time <= #{stockSpecialDayCondition.createTime,jdbcType=DATE} ]]>
				</if>
				<if test="stockSpecialDayCondition.lastEditTime != null">
					and last_edit_time = #{stockSpecialDayCondition.lastEditTime}
				</if>
				<if test="stockSpecialDayCondition.lastEditTime != null">
					and <![CDATA[ last_edit_time >= #{stockSpecialDayCondition.lastEditTime,jdbcType=DATE} ]]>
				</if>
				<if test="stockSpecialDayCondition.lastEditTime != null">
					and <![CDATA[ last_edit_time <= #{stockSpecialDayCondition.lastEditTime,jdbcType=DATE} ]]>
				</if>
				<if test="stockSpecialDayCondition.remark != null">
					and remark like '${stockSpecialDayCondition.remark}'
				</if>
			</where>
			LIMIT #{rowIndex},#{pageSize};
		</script>
	""")
	@ResultMap("StockSpecialDayMap")
	List<StockSpecialDay> queryList(@Param("stockSpecialDayCondition") StockSpecialDay stockSpecialDayCondition,
							@Param("rowIndex") int rowIndex,
							@Param("pageSize") int pageSize);

	@Select("""
		<script>
			SELECT
				count(1)
			FROM
				tb_coldot_stock_special_day
			<where>
				<if test="stockSpecialDayCondition.recordID != null">
					and record_id = #{stockSpecialDayCondition.recordID}
				</if>
				<if test="stockSpecialDayCondition.beginDate != null">
					and begin_date = #{stockSpecialDayCondition.beginDate}
				</if>
				<if test="stockSpecialDayCondition.beginDate != null">
					and <![CDATA[ begin_date >= #{stockSpecialDayCondition.beginDate,jdbcType=DATE} ]]>
				</if>
				<if test="stockSpecialDayCondition.beginDate != null">
					and <![CDATA[ begin_date <= #{stockSpecialDayCondition.beginDate,jdbcType=DATE} ]]>
				</if>
				<if test="stockSpecialDayCondition.endDate != null">
					and end_date = #{stockSpecialDayCondition.endDate}
				</if>
				<if test="stockSpecialDayCondition.endDate != null">
					and <![CDATA[ end_date >= #{stockSpecialDayCondition.endDate,jdbcType=DATE} ]]>
				</if>
				<if test="stockSpecialDayCondition.endDate != null">
					and <![CDATA[ end_date <= #{stockSpecialDayCondition.endDate,jdbcType=DATE} ]]>
				</if>
				<if test="stockSpecialDayCondition.category != null">
					and category = #{stockSpecialDayCondition.category}
				</if>
				<if test="stockSpecialDayCondition.context != null">
					and context like '${stockSpecialDayCondition.context}'
				</if>
				<if test="stockSpecialDayCondition.flag != null">
					and flag = #{stockSpecialDayCondition.flag}
				</if>
				<if test="stockSpecialDayCondition.createTime != null">
					and create_time = #{stockSpecialDayCondition.createTime}
				</if>
				<if test="stockSpecialDayCondition.createTime != null">
					and <![CDATA[ create_time >= #{stockSpecialDayCondition.createTime,jdbcType=DATE} ]]>
				</if>
				<if test="stockSpecialDayCondition.createTime != null">
					and <![CDATA[ create_time <= #{stockSpecialDayCondition.createTime,jdbcType=DATE} ]]>
				</if>
				<if test="stockSpecialDayCondition.lastEditTime != null">
					and last_edit_time = #{stockSpecialDayCondition.lastEditTime}
				</if>
				<if test="stockSpecialDayCondition.lastEditTime != null">
					and <![CDATA[ last_edit_time >= #{stockSpecialDayCondition.lastEditTime,jdbcType=DATE} ]]>
				</if>
				<if test="stockSpecialDayCondition.lastEditTime != null">
					and <![CDATA[ last_edit_time <= #{stockSpecialDayCondition.lastEditTime,jdbcType=DATE} ]]>
				</if>
				<if test="stockSpecialDayCondition.remark != null">
					and remark like '${stockSpecialDayCondition.remark}'
				</if>
			</where>
		</script>
	""")
	int queryCount(@Param("stockSpecialDayCondition") StockSpecialDay stockSpecialDayCondition);

	@Insert("""
		<script>
			INSERT INTO tb_coldot_stock_special_day (
				begin_date,
				end_date,
				category,
				context,
				flag,
				create_time,
				last_edit_time,
				remark
			) VALUES (
				#{beginDate},
				#{endDate},
				#{category},
				#{context},
				#{flag},
				#{createTime},
				#{lastEditTime},
				#{remark}
			)
		</script>
	""")
	@Options(useGeneratedKeys = true, keyColumn = "record_id", keyProperty = "recordID")
	int insert(StockSpecialDay stockSpecialDay);

	@Update("""
		<script>
			UPDATE tb_coldot_stock_special_day
			<set>
				<if test="beginDate != null">begin_date=#{beginDate},</if>
				<if test="endDate != null">end_date=#{endDate},</if>
				<if test="category != null">category=#{category},</if>
				<if test="context != null">context=#{context},</if>
				<if test="flag != null">flag=#{flag},</if>
				<if test="createTime != null">create_time=#{createTime},</if>
				<if test="lastEditTime != null">last_edit_time=#{lastEditTime},</if>
				<if test="remark != null">remark=#{remark}</if>
			</set>
			WHERE
				record_id = #{recordID}
		</script>
	""")
	int update(StockSpecialDay stockSpecialDay);

	@Delete("""
		<script>
			DELETE FROM tb_coldot_stock_special_day
			WHERE
				record_id = #{recordID}
		</script>
	""")
	int delete(Long recordID);

	@Delete("""
		<script>
			DELETE FROM tb_coldot_stock_special_day
			WHERE
				record_id IN
				<foreach collection="list" item="recordID" open="(" separator="," close=")">
					#{recordID}
				</foreach>
		</script>
	""")
	int deleteBatch(List<Long> idList);

}